package com.xxgc.eow.service.impl;

import com.xxgc.eow.entity.Admin;
import com.xxgc.eow.mapper.AdminMapper;
import com.xxgc.eow.service.IAdminService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 管理员表 服务实现类
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-19
 */
@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements IAdminService {

    @Resource
    private AdminMapper adminMapper;

    @Override
    public List<Admin> getAdminAll() {
        return adminMapper.selectAll();
    }

    @Override
    public int delAdminById(int adminId) {
        return adminMapper.deleteByPrimaryKey(adminId);
    }

    @Override
    public int addAdmin(Admin admin) {
        return adminMapper.insert(admin);
    }

    @Override
    public int updatAdmin(Admin admin) {
        return adminMapper.updateByPrimaryKey(admin);
    }

    @Override
    public Admin getAdminBYName(String AdminName) {
        return adminMapper.selectByAdminName(AdminName);
    }

    @Override
    public int Login(Admin admin) {
        Admin admin1 = adminMapper.selectByAdminName(admin.getAdminName());
        if (admin1 == null){
            return 0;
        }else {
            if (admin1.getAdminPassword().equals(admin.getAdminPassword())){
                return 1;
            }else {
                return -1;
            }
        }
    }
}
